package ninja.awesome.game.gameobject;

import java.util.Random;

import ninja.awesome.framework.Graphics;
import ninja.awesome.framework.Image;
import ninja.awesome.game.MainGameScreen;
import ninja.awesome.game.compat.Rectangle;
import ninja.awesome.game.main.Animation;
import ninja.awesome.game.main.Controller;
import ninja.awesome.game.main.Sprites;

public class Bush extends GameObj {
	private int speed = 10;
	private Image[] image;
	private Random gen;
	private int left = 0;
	int right = 1;
	Random r = new Random();

	private double imageWidth = 0;
	private double imageHeight = 0;
	private boolean buildingCollide = false;
	Sprites s;
	MainGameScreen game;
	Controller c;
	Animation anim;
	int whatBush = 0;
	int level = 0;

	public Bush(int x, int y, MainGameScreen game, Controller c, Sprites s) {
		super(x, y);

		this.game = game;
		this.c = c;

		whatBush = 0;
		image = s.getBushSprite(whatBush);
		if (whatBush == 0) {
			imageWidth = 1908;
			imageHeight = 93;
		} else if (whatBush == 1) {
			imageWidth = 642;
			imageHeight = 88;
		} else {
			imageWidth = 269;
			imageWidth = 84;

		}// bush can be varied depending on level of stage!
			// we have not changed

		anim = new Animation(0, image[0], imageHeight, imageWidth, 1);

	}

	public void update() {
		if (game.getBuilding_Block()) {
			right = 0; // to make road not movable! going right
		} else
			right = 1;

		if (game.getNinja().getDirection().equals("left")) {
			xLoc -= game.getNinja().getSpeedX() * 1;
			if (xLoc > 0) {
				if (c.getBush1().size() < 4 || c.getBush2().size() < 4)
					c.spawnBush(-1);
				else if (xLoc > 2000)
					c.removeBush(this);

			}
		} else if (game.getNinja().getDirection().equals("right")) {
			xLoc -= game.getNinja().getSpeedX() * right;
			if (xLoc < 0) {
				if (c.getBush1().size() < 4 || c.getBush2().size() < 4)
					c.spawnBush(1);
				else if (xLoc < -2000)
					c.removeBush(this);
			}
		}

	}

	public void draw(Graphics g) {
		anim.drawAnimation(g, xLoc, yLoc);
	}

	public int getX() {
		return xLoc;
	}

	public int getY() {
		return yLoc;
	}

	public void SetX(int x) {
		this.xLoc = x;
	}

	public void SetY(int y) {
		this.yLoc = y;
	}

	public Rectangle getBounds() {
		return new Rectangle(xLoc, yLoc, (int) imageWidth, (int) imageHeight);
	}

}
